﻿using msBsc.SvRef;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Public
{
    public partial class wfUserLogin : msBsc.Cls.BPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindControls();
            }
        }
        private void BindControls()
        {
            if (!IsPostBack)
            {
            }
        }

        //登录
        private void Login()
        {
            string account = this.GetParamHtValue("account");
            string password = this.GetParamHtValue("password");
            string code = this.GetParamHtValue("code");
            if (string.IsNullOrEmpty(account))
            {
                this.SetContrlValue("login_notice", "*用户名不能为空");
            }

            if (string.IsNullOrEmpty(password))
            {
                this.SetContrlValue("login_notice", "*密码不能为空");
            }

            //if (!CString.IsEmail(account.Trim()))
            //{
            //    this.SetContrlValue("login_notice", "*账户只能是邮箱");
            //}

            if (!CString.IsPassword(password.Trim()))
            {
                this.SetContrlValue("login_notice", "*密码只能是6~16未字母或字符组成");
            }

            if (code != (string)GetSession(this.sCurrPageRadom + msBsc.Cls.ValidateCode.VALIDATECODEKEY, "2"))
            {
                this.ExecJScript("jQuery.getValidateImg('imgValidata');");
                this.SetContrlValue("login_notice", "验证码错误或已过期，请重新录入！");
                return;
            }


            string ret = UserInfo.LoginCustomer(account, password);
            password = msBsc.AppLogic.Cfg.DesCry.encMe(password, "zbhpass");
            if (ret != "OK")
            {
                if (ret == "OK1")
                {
                    this.ExecJScript("setCookie('" + account + "','" + password + "');window.location.href='/wp_ModifyAgentDjackPwd.htm';");
                    return;
                }

                this.SetContrlValue("login_notice", ret);
            }
            else
            {
                if (UserInfo.OperType == "3")
                {
                    this.ExecJScript(@"setCookie('" + account + "','" + password + "');window.location.href='/ws_AgentDjackInfo.htm'");
                    return;
                }

                this.ExecJScript(@"setCookie('" + account + "','" + password + "');susccLogin()");
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                string password = this.GetParamHtValue("password");
                if (!string.IsNullOrEmpty(password))
                {

                    password = msBsc.AppLogic.Cfg.DesCry.uncMe(password, "zbhpass");
                    this.ExecJScript(@"$('#pwdPassword').val('" + password + "')");
                }
                base.DoAction();
            }
            else if (this.strAction == "login")
            {
                Login();
            }
        }
    }
}